package com.atguigu.mq.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.mq.constant.PunchConst;
import com.atguigu.mq.helper.HttpRequestHelper;
import com.atguigu.mq.service.PunchClockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author KEIO  on 2021/9/1.
 * @version 1.0
 */
@Slf4j
@Service
public class PunchClockServiceImpl implements PunchClockService {

    @Value("${PunchClock.name}")
    private String name;

    @Value("${PunchClock.xh}")
    private String xh;

    @Value("${PunchClock.xb}")
    private String xb;

    @Value("${PunchClock.openid}")
    private String openid;

    @Value("${PunchClock.xxdz}")
    private String xxdz;

    @Value("${PunchClock.szdq}")
    private String szdq;

    @Value("${PunchClock.locationBig}")
    private String locationBig;

    @Value("${PunchClock.locationSmall}")
    private String locationSmall;

    @Value("${PunchClock.latitude}")
    private Double latitude;

    @Value("${PunchClock.longitude}")
    private Double longitude;

    @Value("${PunchClock.ywjcqzbl}")
    private String ywjcqzbl;


    @Value("${PunchClock.ywjchblj}")
    private String ywjchblj;


    @Value("${PunchClock.xjzdywqzbl}")
    private String xjzdywqzbl;

    @Value("${PunchClock.twsfzc}")
    private String twsfzc;

    @Value("${PunchClock.ywytdzz}")
    private String ywytdzz;

    @Value("${PunchClock.beizhu}")
    private String beizhu;



    @Override
    public void punchClockRightNow() {
        SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
        SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
        String day = dayFormat.format(new Date());
        String hour = hourFormat.format(new Date());
        log.info("当前小时{}", hour);

        String mrdkkey = PunchConst.r[Integer.parseInt(day)] + PunchConst.u[Integer.parseInt(hour)];



        Long times = System.currentTimeMillis()/1000;
        String timestamp = times.toString();
        /*
        times *= 1000;
        String timestamp2 = times.toString().substring(0, 10);

        log.info("timestamp:{}", timestamp);
        log.info("timestamp2:{}", timestamp2);
        if(timestamp.equalsIgnoreCase(timestamp2)){
            log.info("这两个时间戳根本没有不同");
        }
         */


        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        params.put("xh", xh);
        params.put("xb", xb);
        params.put("openid", openid);
        params.put("xxdz", xxdz);
        params.put("szdq", szdq);
        params.put("locationBig", locationBig);
        params.put("locationSmall", locationSmall);
        params.put("latitude",  latitude);
        params.put("longitude", longitude);
        params.put("ywjcqzbl", ywjcqzbl);
        params.put("ywjchblj", ywjchblj);
        params.put("xjzdywqzbl", xjzdywqzbl);
        params.put("twsfzc", twsfzc);
        params.put("ywytdzz", ywytdzz);
        params.put("beizhu", beizhu);
        params.put("mrdkkey", mrdkkey);
        params.put("timestamp", timestamp);
        JSONObject response = HttpRequestHelper.sendHttpsRequest(params, PunchConst.RequestUrl);// http
        log.info("返回结果{}" , response.toJSONString());

//        if(null == response || 200 != response.getIntValue("code")) {
//
//        }

        /*
          name: 娄奚文炀
            xh: '2019211634'
            xb: 男
            openid: oIaII0YAmdvUbkinP-0cQ1acJsHA
            xxdz: 重庆邮电大学
            szdq: '重庆市,重庆市,大渡口区'
            locationBig: '中国,重庆市,重庆市,大渡口区'
            locationSmall: 重庆市大渡口区钢城大道南段121号
            latitude: 29.48408
            longitude: 106.48225
            ywjcqzbl: 低风险
            ywjchblj: 无
            xjzdywqzbl: 无
            twsfzc: 是
            ywytdzz: 无
            beizhu: 无
         */


    }
}
